package com.bestcem.xm.member.mq.receiver;//package com.bestcem.xm.member.mq.receiver;
//
//import com.bestcem.xm.member.mq.message.GroupDeletedMessage;
//import com.bestcem.xm.member.service.GroupService;
//import com.bestcem.xm.util.MsgPackFormatUtil;
//import com.bestcem.xm.common.core.domain.web.ServiceResult;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//
///**
// * 分组删除 消费者
// *
// * @author ympan <yuming.pan@idiaoyan.com>
// * @version v1.0
// * @date 16:53 2022/1/17
// */
//@Slf4j
//@Component
//public class GroupDeletedReceiver {
//    private static final Logger EMAIL_LOG = LoggerFactory.getLogger("EmailErrorLog");
//
//    @Autowired
//    private GroupService groupService;
//
//    @RabbitListener(queues = "#{memberGroupDeletedQueue.name}",
//            ackMode = "MANUAL",
//            concurrency = "${app.member.group-condition-mod-config.receiver-consume-concurrency:4}",
//            containerFactory = "memberGroupDeletedFactory")
//    public void receive(Message message, Channel channel) throws IOException {
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        try {
//            MsgPackFormatUtil.MqMessage mqMessage = MsgPackFormatUtil.mqDecode(message.getBody());
//            if (mqMessage == null) {
//                EMAIL_LOG.error("【联系人】receiver decode group deleted message failed, abandon message, message: {}", message);
//                channel.basicNack(deliveryTag, false, false);
//                return;
//            }
//            if (log.isInfoEnabled()) {
//                log.info("【联系人】received group deleted message: {}", mqMessage);
//            }
//
//            GroupDeletedMessage groupDeletedMessage = MsgPackFormatUtil.mapToObj(mqMessage.getData(),
//                    GroupDeletedMessage.class);
//
//            ServiceResult<Void> result = groupService.updateMemberGroups(groupDeletedMessage);
//            if (result.isSuccess()) {
//                if (log.isInfoEnabled()) {
//                    log.info("【联系人】receiver process group deleted message success, message: {}", groupDeletedMessage);
//                }
//            } else {
//                log.error("【联系人】receiver process group deleted message failed, message: {}", groupDeletedMessage);
//            }
//            channel.basicAck(deliveryTag, false);
//        } catch (Exception e) {
//            EMAIL_LOG.error("【联系人】process group deleted message failed, abandon message, message: {}", message, e);
//            channel.basicNack(deliveryTag, false, false);
//        }
//    }
//}
//